package com.dykj.fireFighting.web.base.analysis.controller;

import com.dykj.fireFighting.api.base.analysis.entity.AreaLevel;
import com.dykj.fireFighting.api.base.analysis.entity.AreaMap;
import com.dykj.fireFighting.api.base.analysis.entity.BusinessLevel;
import com.dykj.fireFighting.api.base.analysis.entity.BusinessMap;
import com.dykj.fireFighting.api.base.analysis.service.IBusinessAnalysisService;
import com.dykj.fireFighting.api.base.analysis.service.ILevelAnalysisService;
import com.dykj.fireFighting.common.core.api.CommonResult;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.apache.dubbo.config.annotation.DubboReference;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.List;

/*
 * 排名分析
 */
@Slf4j
@Api(value = "排名分析", tags = {"排名分析"})
@RestController
@RequestMapping("/analysis")
public class LevelAnalysisController {
    @DubboReference
    private ILevelAnalysisService iLevelAnalysisService;

    @DubboReference
    private IBusinessAnalysisService iBusinessAnalysisService;

    @ApiOperation(value = "区域地图", notes = "区域地图")
    @GetMapping("/getAreaMap")
    public CommonResult<List<AreaMap>> getAreaMap (String beginTime,String endTime,Integer alarmType){
        List<AreaMap> list = new ArrayList<>();
        if (alarmType == 1) {
            list = iLevelAnalysisService.getFireAlarmAreaMap(beginTime, endTime);
        }
        if (alarmType == 2){
            list = iLevelAnalysisService.getFaultAreaMap(beginTime, endTime);
        }
        if (alarmType == 3){
            list = iLevelAnalysisService.getEarlyWarningAreaMap(beginTime, endTime);
        }
        return CommonResult.success(list);
    }

    @ApiOperation(value = "区域排名", notes = "区域排名")
    @GetMapping("/getAreaLevel")
    public CommonResult<List<AreaLevel>> getAreaLevel (String beginTime,Integer alarmType,Integer type){
        List<AreaLevel> list = new ArrayList<>();

        String str = type+""+alarmType;
        switch (str) {
            case "11":
                list = iLevelAnalysisService.getFireAlarmAreaLevelByYear(beginTime);
                break;
            case "12":
                list = iLevelAnalysisService.getFaultAreaLevelByYear(beginTime);
                break;
            case "13":
                list = iLevelAnalysisService.getEarlyWarningAreaLevelByYear(beginTime);
                break;
            case "21":
                list = iLevelAnalysisService.getFireAlarmAreaLevelByQuarter(beginTime);
                break;
            case "22":
                list = iLevelAnalysisService.getFaultAreaLevelByQuarter(beginTime);
                break;
            case "23":
                list = iLevelAnalysisService.getEarlyWarningAreaLevelByQuarter(beginTime);
                break;
            case "31":
                list = iLevelAnalysisService.getFireAlarmAreaLevelByMonth(beginTime);
                break;
            case "32":
                list = iLevelAnalysisService.getFaultAreaLevelByMonth(beginTime);
                break;
            case "33":
                list = iLevelAnalysisService.getEarlyWarningAreaLevelByMonth(beginTime);
                break;
        }
        return CommonResult.success(list);
    }

    @ApiOperation(value = "行业地图", notes = "行业地图")
    @GetMapping("/getBusinessMap")
    public CommonResult<List<BusinessMap>> getBusinessMap (String beginTime, String endTime, Integer alarmType){
        List<BusinessMap> list = new ArrayList<>();
        if (alarmType == 1) {
            list = iBusinessAnalysisService.getFireAlarmBusinessMap(beginTime, endTime);
        }
        if (alarmType == 2){
            list = iBusinessAnalysisService.getFaultBusinessMap(beginTime, endTime);
        }
        if (alarmType == 3){
            list = iBusinessAnalysisService.getEarlyWarningBusinessMap(beginTime, endTime);
        }
        return CommonResult.success(list);
    }

    @ApiOperation(value = "行业排名", notes = "行业排名")
    @GetMapping("/getBusinessLevel")
    public CommonResult<List<BusinessLevel>> getBusinessLevel (String beginTime, Integer alarmType, Integer type){
        List<BusinessLevel> list = new ArrayList<>();

        String str = type+""+alarmType;
        switch (str) {
            case "11":
                list = iBusinessAnalysisService.getFireAlarmBusinessLevelByYear(beginTime);
                break;
            case "12":
                list = iBusinessAnalysisService.getFaultBusinessLevelByYear(beginTime);
                break;
            case "13":
                list = iBusinessAnalysisService.getEarlyWarningBusinessLevelByYear(beginTime);
                break;
            case "21":
                list = iBusinessAnalysisService.getFireAlarmBusinessLevelByQuarter(beginTime);
                break;
            case "22":
                list = iBusinessAnalysisService.getFaultBusinessLevelByQuarter(beginTime);
                break;
            case "23":
                list = iBusinessAnalysisService.getEarlyWarningBusinessLevelByQuarter(beginTime);
                break;
            case "31":
                list = iBusinessAnalysisService.getFireAlarmBusinessLevelByMonth(beginTime);
                break;
            case "32":
                list = iBusinessAnalysisService.getFaultBusinessLevelByMonth(beginTime);
                break;
            case "33":
                list = iBusinessAnalysisService.getEarlyWarningBusinessLevelByMonth(beginTime);
                break;
        }
        return CommonResult.success(list);
    }
}
